package cn.itcast.demo;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class SolrGreateIndexTest {
     @Test
    public void testGreateIndex() throws IOException, SolrServerException {
        //连接服务器  指定solr服务,指定核心
       SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/cor2");

        //创建一个文档
        SolrInputDocument document = new SolrInputDocument();

        //添加字段
        document.addField("id", "10086");
        document.addField("title","中国移动");
        document.addField("price", 98989);

        //添加ddcument到server
         solrServer.add(document);

        //提交请求, 如果没有id就修改参数
        solrServer.commit();
    }
}
